package test;

import java.awt.Color;
import java.awt.Font;
import java.awt.geom.*;
import javax.swing.JFrame;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.*;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.*;
import org.jfree.data.xy.DefaultXYDataset;

public class ProvaGrafoXY {
   public static void main(String[] args) {
      DefaultXYDataset dataset = new DefaultXYDataset();
      dataset.addSeries("Red circles",new double[][]{{1, 2, 3}, {2, 4, 1}});      
      ValueAxis xAxis = new NumberAxis("x");
      ValueAxis yAxis = new NumberAxis("y");
      XYItemRenderer renderer = new XYLineAndShapeRenderer();
      renderer.setSeriesPaint(0, Color.RED);
      renderer.setSeriesPaint(1, Color.BLUE);
      renderer.setSeriesPaint(2, Color.GREEN);
      renderer.setSeriesShape(0, new Ellipse2D.Double(-5, -5, 10, 10));
      renderer.setSeriesShape(1, new Rectangle2D.Double(-5, -5, 10, 10));
      renderer.setSeriesShape(2, new Rectangle2D.Double(-7, -3, 14, 6));
      XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
      JFreeChart chart = new JFreeChart("XYPlot Demo", new Font("Tahoma", 2, 18), plot, true);
      JFrame frame = new JFrame("XY Plot Demo");
      frame.setContentPane(new ChartPanel(chart));
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.pack();
      frame.setVisible(true);
      
      try{
         Thread.sleep(2000);
      } catch(InterruptedException e){}
      dataset.addSeries("Blue squares",new double[][]{{1.3, 2.3, 3.3}, {12, 14, 11}});
      
      try{
         Thread.sleep(2000);
      } catch(InterruptedException e){}
      dataset.addSeries("Green rect",new double[][]{{1.7, 2.7, 3.7}, {7, 9, 6}});
      
      try{
         Thread.sleep(2000);
      } catch(InterruptedException e){}
      dataset.addSeries("Red circles",new double[][]{{10, 20, 30}, {20, 40, 10}});      
   }
}
